package dai.core.base

import dai.core.base.camera.Camera
import org.joml.Matrix4f
import org.joml.Vector3f

class Transformation {
    val projectMatrix = Matrix4f()
    val worldMatrix = Matrix4f()
    val viewMatrix = Matrix4f()

    fun projectMatrix(fov: Float, width: Float, height: Float, near: Float, far: Float): Matrix4f {
        val ratio = width / height
        projectMatrix.identity()
        projectMatrix.perspective(fov,ratio,near,far)
        return projectMatrix
    }

    fun worldMatrix(offset: Vector3f, rotation: Vector3f, scale:Float): Matrix4f {
        worldMatrix.identity()
            .translate(offset)
            .rotateX(Utils.toRadius(rotation.x))
            .rotateY(Utils.toRadius(rotation.y))
            .rotateZ(Utils.toRadius(rotation.z))
            .scale(scale)
        return worldMatrix
    }

    fun viewMatrix(camera: Camera):Matrix4f{
         viewMatrix.identity()
             .lookAt(camera.position,camera.target,camera.up)
        return viewMatrix
    }
}
